package jogs.client.listeners;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JList;

import jogs.client.*;


public class ListMouseListener implements MouseListener
{

	private JList list;
	private String username;
	
	public ListMouseListener(JList _list, String _username)
	{
		list = _list;
		username = _username;
	}
	
	public void mouseClicked(MouseEvent e)
	{
		if(e.getClickCount() == 2)
		{
			Object obj = list.getSelectedValue();
			if (obj == null)
				return;
			try
			{
				ListObject lo = (ListObject)obj;
				if(lo.getType()== 0)
				{
					String room = lo.toString().split(" ")[0];
					lo.send("/join " + room);
				}
				else if (lo.getType() == 2)
				{
					String table = lo.toString().split(" ")[0];
					lo.send("@SIT:" + table);
				}
			}
			catch(Exception exp){}
		}

	}

	public void mouseEntered(MouseEvent arg0)
	{
		// TODO Auto-generated method stub

	}

	public void mouseExited(MouseEvent arg0)
	{
		// TODO Auto-generated method stub

	}

	public void mousePressed(MouseEvent arg0)
	{
		// TODO Auto-generated method stub

	}

	public void mouseReleased(MouseEvent arg0)
	{
		// TODO Auto-generated method stub

	}

}
